<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.key" size="mini" placeholder="参数名" clearable @clear="getDataList()" @blur="getDataList()"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button size="mini" type="success" @click="getDataList()" icon="el-icon-search">查询</el-button>
        <el-button @click="resetForm" size="mini" type="warning" icon="el-icon-refresh-left">重置</el-button>
      </el-form-item>
    </el-form>
    <el-form>
      <el-form-item>
        <el-button-group>
          <el-button size="mini" v-if="isAuth('purchase:purchasesinboundorderdetail:save')" type="primary" @click="addOrUpdateHandle()" icon="el-icon-plus">新增</el-button>
          <el-button size="mini" v-if="isAuth('purchase:purchasesinboundorderdetail:delete')" type="danger" @click="deleteHandle()" icon="el-icon-delete" :disabled="dataListSelections.length <= 0">删除</el-button>
        </el-button-group>
        <el-button-group>
          <el-button size="mini" v-if="isAuth('purchase:purchasesinboundorderdetail:export')" type="info" @click="exportData" class="iconfont icon-topsales">导出</el-button>
          <el-button size="mini" v-if="isAuth('purchase:purchasesinboundorderdetail:import')" type="info" @click="importData()" class="iconfont icon-skip">导入</el-button>
        </el-button-group>
      </el-form-item>
      <el-form-item>
        <el-dialog title="导入数据" :visible.sync="upload.open" width="400px" append-to-body :close-on-click-modal="false">
          <el-upload
                  ref="upload"
                  :limit="1"
                  accept=".xlsx, .xls"
                  :headers="upload.headers"
                  :before-upload="beforeUpload"
                  :action="upload.url"
                  :disabled="upload.isUploading"
                  :on-progress="handleFileUploadProgress"
                  :on-success="handleFileSuccess"
                  :auto-upload="false"
                  :file-list="excelList"
                  :on-remove="onRemoveDr"
                  :on-change="onChangeDr"
                  drag
          >
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">
              将文件拖到此处，或
              <em>点击上传</em>
            </div>
            <div class="el-upload__tip" style="color:red" slot="tip">提示：仅允许导入“xls”或“xlsx”格式文件！</div>
          </el-upload>
          <el-button size="mini" type="success" @click="downloadImportTemplate">下载模板</el-button>
          <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitFileForm">导 入</el-button>
            <el-button @click="cancelFileForm">取 消</el-button>
          </div>
        </el-dialog>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      size="mini"
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;"
      @cell-click="tableDbEdit"
      @cell-dblclick="tableDbEdit"
      :header-cell-style="{ background: '#fcfcfc', color: '#606266', height:'36px'}">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column type="index" header-align="center" align="center" label="#" width="40">
      </el-table-column>
        <el-table-column
        prop="inboundDetailId"
        header-align="center"
        align="center"
        label="">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.inboundDetailId" v-if="showInput == `inboundDetailId${scope.row.Id}`"
                      @blur='blurInput(scope.row, "inboundDetailId", scope.row.inboundDetailId)' v-focus>
            </el-input>
            <span v-else >{{scope.row.inboundDetailId}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="inboundId"
        header-align="center"
        align="center"
        label="入库单id">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.inboundId" v-if="showInput == `inboundId${scope.row.Id}`"
                      @blur='blurInput(scope.row, "inboundId", scope.row.inboundId)' v-focus>
            </el-input>
            <span v-else >{{scope.row.inboundId}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="inboundNo"
        header-align="center"
        align="center"
        label="入库单">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.inboundNo" v-if="showInput == `inboundNo${scope.row.Id}`"
                      @blur='blurInput(scope.row, "inboundNo", scope.row.inboundNo)' v-focus>
            </el-input>
            <span v-else >{{scope.row.inboundNo}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="categoryId"
        header-align="center"
        align="center"
        label="商品类别id">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.categoryId" v-if="showInput == `categoryId${scope.row.Id}`"
                      @blur='blurInput(scope.row, "categoryId", scope.row.categoryId)' v-focus>
            </el-input>
            <span v-else >{{scope.row.categoryId}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="productId"
        header-align="center"
        align="center"
        label="产品id">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.productId" v-if="showInput == `productId${scope.row.Id}`"
                      @blur='blurInput(scope.row, "productId", scope.row.productId)' v-focus>
            </el-input>
            <span v-else >{{scope.row.productId}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="productCode"
        header-align="center"
        align="center"
        label="产品编码">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.productCode" v-if="showInput == `productCode${scope.row.Id}`"
                      @blur='blurInput(scope.row, "productCode", scope.row.productCode)' v-focus>
            </el-input>
            <span v-else >{{scope.row.productCode}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="productName"
        header-align="center"
        align="center"
        label="产品名称">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.productName" v-if="showInput == `productName${scope.row.Id}`"
                      @blur='blurInput(scope.row, "productName", scope.row.productName)' v-focus>
            </el-input>
            <span v-else >{{scope.row.productName}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="barCode"
        header-align="center"
        align="center"
        label="条形码">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.barCode" v-if="showInput == `barCode${scope.row.Id}`"
                      @blur='blurInput(scope.row, "barCode", scope.row.barCode)' v-focus>
            </el-input>
            <span v-else >{{scope.row.barCode}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="genericName"
        header-align="center"
        align="center"
        label="通用名称">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.genericName" v-if="showInput == `genericName${scope.row.Id}`"
                      @blur='blurInput(scope.row, "genericName", scope.row.genericName)' v-focus>
            </el-input>
            <span v-else >{{scope.row.genericName}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="standard"
        header-align="center"
        align="center"
        label="规格">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.standard" v-if="showInput == `standard${scope.row.Id}`"
                      @blur='blurInput(scope.row, "standard", scope.row.standard)' v-focus>
            </el-input>
            <span v-else >{{scope.row.standard}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="unit"
        header-align="center"
        align="center"
        label="单位">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.unit" v-if="showInput == `unit${scope.row.Id}`"
                      @blur='blurInput(scope.row, "unit", scope.row.unit)' v-focus>
            </el-input>
            <span v-else >{{scope.row.unit}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="producingArea"
        header-align="center"
        align="center"
        label="产地">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.producingArea" v-if="showInput == `producingArea${scope.row.Id}`"
                      @blur='blurInput(scope.row, "producingArea", scope.row.producingArea)' v-focus>
            </el-input>
            <span v-else >{{scope.row.producingArea}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="produceFactory"
        header-align="center"
        align="center"
        label="生产单位">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.produceFactory" v-if="showInput == `produceFactory${scope.row.Id}`"
                      @blur='blurInput(scope.row, "produceFactory", scope.row.produceFactory)' v-focus>
            </el-input>
            <span v-else >{{scope.row.produceFactory}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="approvalNo"
        header-align="center"
        align="center"
        label="批准文号">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.approvalNo" v-if="showInput == `approvalNo${scope.row.Id}`"
                      @blur='blurInput(scope.row, "approvalNo", scope.row.approvalNo)' v-focus>
            </el-input>
            <span v-else >{{scope.row.approvalNo}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="dosageForm"
        header-align="center"
        align="center"
        label="剂型">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.dosageForm" v-if="showInput == `dosageForm${scope.row.Id}`"
                      @blur='blurInput(scope.row, "dosageForm", scope.row.dosageForm)' v-focus>
            </el-input>
            <span v-else >{{scope.row.dosageForm}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="batchNo"
        header-align="center"
        align="center"
        label="批号">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.batchNo" v-if="showInput == `batchNo${scope.row.Id}`"
                      @blur='blurInput(scope.row, "batchNo", scope.row.batchNo)' v-focus>
            </el-input>
            <span v-else >{{scope.row.batchNo}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="produceDate"
        header-align="center"
        align="center"
        label="生产日期">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.produceDate" v-if="showInput == `produceDate${scope.row.Id}`"
                      @blur='blurInput(scope.row, "produceDate", scope.row.produceDate)' v-focus>
            </el-input>
            <span v-else >{{scope.row.produceDate}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="expiryDate"
        header-align="center"
        align="center"
        label="有效期">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.expiryDate" v-if="showInput == `expiryDate${scope.row.Id}`"
                      @blur='blurInput(scope.row, "expiryDate", scope.row.expiryDate)' v-focus>
            </el-input>
            <span v-else >{{scope.row.expiryDate}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="purchaseCount"
        header-align="center"
        align="center"
        label="采购金额">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.purchaseCount" v-if="showInput == `purchaseCount${scope.row.Id}`"
                      @blur='blurInput(scope.row, "purchaseCount", scope.row.purchaseCount)' v-focus>
            </el-input>
            <span v-else >{{scope.row.purchaseCount}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="qualifiedCount"
        header-align="center"
        align="center"
        label="合格数量">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.qualifiedCount" v-if="showInput == `qualifiedCount${scope.row.Id}`"
                      @blur='blurInput(scope.row, "qualifiedCount", scope.row.qualifiedCount)' v-focus>
            </el-input>
            <span v-else >{{scope.row.qualifiedCount}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="purchasePrice"
        header-align="center"
        align="center"
        label="采购价格">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.purchasePrice" v-if="showInput == `purchasePrice${scope.row.Id}`"
                      @blur='blurInput(scope.row, "purchasePrice", scope.row.purchasePrice)' v-focus>
            </el-input>
            <span v-else >{{scope.row.purchasePrice}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="purchaseFee"
        header-align="center"
        align="center"
        label="采购金额">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.purchaseFee" v-if="showInput == `purchaseFee${scope.row.Id}`"
                      @blur='blurInput(scope.row, "purchaseFee", scope.row.purchaseFee)' v-focus>
            </el-input>
            <span v-else >{{scope.row.purchaseFee}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="keyNo"
        header-align="center"
        align="center"
        label="f4流水号">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.keyNo" v-if="showInput == `keyNo${scope.row.Id}`"
                      @blur='blurInput(scope.row, "keyNo", scope.row.keyNo)' v-focus>
            </el-input>
            <span v-else >{{scope.row.keyNo}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="lastPurchasePrice"
        header-align="center"
        align="center"
        label="上次进价">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.lastPurchasePrice" v-if="showInput == `lastPurchasePrice${scope.row.Id}`"
                      @blur='blurInput(scope.row, "lastPurchasePrice", scope.row.lastPurchasePrice)' v-focus>
            </el-input>
            <span v-else >{{scope.row.lastPurchasePrice}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="retailPrice"
        header-align="center"
        align="center"
        label="原零售价">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.retailPrice" v-if="showInput == `retailPrice${scope.row.Id}`"
                      @blur='blurInput(scope.row, "retailPrice", scope.row.retailPrice)' v-focus>
            </el-input>
            <span v-else >{{scope.row.retailPrice}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="newRetailPrice"
        header-align="center"
        align="center"
        label="零售价">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.newRetailPrice" v-if="showInput == `newRetailPrice${scope.row.Id}`"
                      @blur='blurInput(scope.row, "newRetailPrice", scope.row.newRetailPrice)' v-focus>
            </el-input>
            <span v-else >{{scope.row.newRetailPrice}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="memberPrice"
        header-align="center"
        align="center"
        label="原会员价">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.memberPrice" v-if="showInput == `memberPrice${scope.row.Id}`"
                      @blur='blurInput(scope.row, "memberPrice", scope.row.memberPrice)' v-focus>
            </el-input>
            <span v-else >{{scope.row.memberPrice}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="newMemberPrice"
        header-align="center"
        align="center"
        label="会员价">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.newMemberPrice" v-if="showInput == `newMemberPrice${scope.row.Id}`"
                      @blur='blurInput(scope.row, "newMemberPrice", scope.row.newMemberPrice)' v-focus>
            </el-input>
            <span v-else >{{scope.row.newMemberPrice}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="storeId"
        header-align="center"
        align="center"
        label="门店id">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.storeId" v-if="showInput == `storeId${scope.row.Id}`"
                      @blur='blurInput(scope.row, "storeId", scope.row.storeId)' v-focus>
            </el-input>
            <span v-else >{{scope.row.storeId}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="storeName"
        header-align="center"
        align="center"
        label="门店名称">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.storeName" v-if="showInput == `storeName${scope.row.Id}`"
                      @blur='blurInput(scope.row, "storeName", scope.row.storeName)' v-focus>
            </el-input>
            <span v-else >{{scope.row.storeName}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="storeCode"
        header-align="center"
        align="center"
        label="门店编码">
        <template slot-scope="scope">
                      <el-input size="mini" v-model="scope.row.storeCode" v-if="showInput == `storeCode${scope.row.Id}`"
                      @blur='blurInput(scope.row, "storeCode", scope.row.storeCode)' v-focus>
            </el-input>
            <span v-else >{{scope.row.storeCode}}</span>
                  </template>
      </el-table-column>
          <el-table-column
        prop="createTime"
        header-align="center"
        align="center"
        label="创建时间">
        <template slot-scope="scope">
                            </template>
      </el-table-column>
          <el-table-column
        prop="updateTime"
        header-align="center"
        align="center"
        label="修改时间">
        <template slot-scope="scope">
                            </template>
      </el-table-column>
          <el-table-column
        prop="createUsername"
        header-align="center"
        align="center"
        label="创建人">
        <template slot-scope="scope">
                            </template>
      </el-table-column>
                <el-table-column
        prop="updateUsername"
        header-align="center"
        align="center"
        label="修改人">
        <template slot-scope="scope">
                            </template>
      </el-table-column>
                <el-table-column
        prop="status"
        header-align="center"
        align="center"
        label="是否可用 1:是">
        <template slot-scope="scope">
                        <el-switch size="mini" v-model="scope.row.status" @change="saveHandle(scope.row)"></el-switch>
                  </template>
      </el-table-column>
                      <el-table-column
        prop="remark"
        header-align="center"
        align="center"
        label="备注">
        <template slot-scope="scope">
                        <span v-html="scope.row.remark"></span>
                  </template>
      </el-table-column>
        <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button size="mini" type="text" v-if="isAuth('purchase:purchasesinboundorderdetail:save')" @click="saveHandle(scope.row)">保存</el-button>
          <el-button size="mini" type="text" v-if="isAuth('purchase:purchasesinboundorderdetail:update')" @click="addOrUpdateHandle(scope.row.inboundDetailId)">修改</el-button>
          <el-button size="mini" type="text" v-if="isAuth('purchase:purchasesinboundorderdetail:delete')" @click="deleteHandle(scope.row.inboundDetailId)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
  import AddOrUpdate from './purchasesinboundorderdetail-add-or-update'
  import {downLoadFile} from '@/utils/myUtil.js'
  import { Loading } from "element-ui"
  export default {
    data () {
      return {
        dataForm: {
          key: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false,
        showInput: "",
        oldData: {},
        currentData: {},
        //导入
        upload: {
          // 是否显示弹出层（用户导入）
          open: false,
          // 弹出层标题（用户导入）
          title: "导入药品数据",
          // 是否禁用上传
          isUploading: false,
          // 是否更新已经存在的用户数据
          // updateSupport: 0,
          // 设置上传的请求头部
          // 上传的地址
          url: `${window.SITE_CONFIG.baseUrl}/purchase/purchasesinboundorderdetail/importData`
        },
        //上传的文件
        excelList:[],
      }
    },
    components: {
      AddOrUpdate
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      async getDataList () {
        this.dataListLoading = true
        const res = await this.$http({
          url: `/purchase/purchasesinboundorderdetail/page`,
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'dataForm': this.dataForm
          })
        })
        let data = res.data
        if (data && data.code === 0) {
          this.dataList = data.page.list
          this.totalPage = data.page.totalCount
          this.dataList.forEach(item => {
            item.status = item.status == 1 ? true : false
          })
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.inboundDetailId
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then( async () => {
          const res = await this.$http({
            url: `/purchase/purchasesinboundorderdetail/delete`,
            method: 'delete',
            data: this.$http.adornData(ids, false)
          })
          let data = res.data
          if (data && data.code === 0) {
            this.$message({
                    message: '操作成功',
                    type: 'success',
                    duration: 1500,
                    onClose: () => {
              this.getDataList()
            }
          })
          } else {
            this.$message.error(data.msg)
          }
        })
      },
      resetForm(){
        this.$nextTick(() =>{
          this.dataForm = this.$options.data().dataForm
          this.getDataList()
        })
      },
      async saveHandle(row){
        row.status = row.status ? 1 : 0
        const res = await this.$http({
          url:`/purchase/purchasesinboundorderdetail/update`,
          method: 'post',
          data: this.$http.adornData(row)
        });
        let data = res.data
        if (data && data.code !== 0) {
          row.status = !row.status;
          return this.$message.error('修改失败!');
        }
        this.$message.success('更新成功！');
        this.getDataList();
      },
      // 当input失去光标后进行的操作
      async blurInput(row, name, value) {
        // 判断数据是否有所改变，如果数据有改变则调用修改接口
        if (this.oldData[name] != value) {
          row[name] = value
          if(value === true){
            row[name] = 1
          }else if(value === false){
            row[name] = 0
          }
        }
        this.showInput = ""
        this.currentData = row
      },
      tableDbEdit(row, column, event) {
        this.showInput = column.property + row.inboundDetailId;
        this.oldData[column.property] = row[column.property];
      },
      async exportData(){
        const res = await this.$http({
          url:`/purchase/purchasesinboundorderdetail/exportData`,
          method: 'get',
          responseType: 'blob',
          params: this.$http.adornParams()
        });
        downLoadFile(res)
      },
      beforeUpload(file) {
        //截取文件后缀名
        const fileName = file.name.substring(file.name.lastIndexOf('.'));
        if(fileName.toLowerCase()!='.xls' && fileName.toLowerCase() !='.xlsx'){
          this.$message.error('文件必须为.xls或xlsx类型');
          this.fileList = [];
          return false;
        };
        //读取文件大小
        var fileSize = file.size;
        if(fileSize > 3249576){
          this.uploadShowDialog = false;
          this.$message({
            type:'error',
            showClose:true,
            duration:3000,
            message:'文件不能大于3M!'
          });
          return false;
        }
      },
      // excel表上传
      handleUploadChange(file, fileList) {
        if (fileList.length > 0) {
          // 这一步，是展示最后一次选择的文件
          this.fileList = [fileList[fileList.length - 1]];    }
      },
      //导入按钮
      handleImport(){
        this.upload.open = true;
      },
      //导入提交
      async submitFileForm(){
        if (this.excelList.length === 0) {
          this.$message.warning("请选择文件");
          return;
        }
        if (this.excelList.length > 1) {
          this.$message.warning("每次只能提交一个文件");
          return;
        }
        let formData = new FormData();
        this.excelList.forEach((item) => {
          formData.append("file", item.raw);
        });
        let loadingInstance = Loading.service({
          lock: true, //lock的修改符--默认是false
          text: "导入中", //显示在加载图标下方的加载文案
          spinner: "el-icon-loading", //自定义加载图标类名
          background: "rgba(0, 0, 0, 0.7)", //遮罩层颜色
          target: document.querySelector("#futureTransferDialog"), //loadin覆盖的dom元素节点
        });
        const res = await this.$http({
          url: this.upload.url,
          method: 'post',
          data: formData
        })
        let data = res.data
        if (data && data.code === 0) {
          loadingInstance.close();
          this.$message({
            type: "success",
            message: "导入成功!",
          });
          this.getDataList();
        }
        this.excelList = [];
        this.upload.open = false;
        loadingInstance.close();
        this.dataListLoading = false
      },
      //下载导入模板
      downloadImportTemplate(){
        window.location.href = "http://file.asdzy.com/upload/files/film/品牌模板.xlsx"
      },
      // 文件上传成功处理
      handleFileSuccess(response, file, fileList) {
        this.excelList = fileList;
      },
      // 文件上传中处理
      handleFileUploadProgress(event, file, fileList) {
        this.upload.isUploading = true;
      },
      onChangeDr(file, fileList) {
        this.excelList = fileList;
      },
      onRemoveDr(file, fileList) {
        this.excelList = fileList;
      },
      cancelFileForm(){
        this.upload.open = false
        this.excelList = [];
      },
    },

    directives: {
      // 通过自定义指令实现的表单自动获得光标的操作
      focus: {
        inserted: function(el) {
          if (el.tagName.toLocaleLowerCase() == "input") {
            el.focus()
          } else {
            if (el.getElementsByTagName("input")) {
              el.getElementsByTagName("input")[0].focus()
            }
          }
          el.focus()
        }
      },
      focusTextarea: {
        inserted: function(el) {
          if (el.tagName.toLocaleLowerCase() == "textarea") {
            el.focus()
          } else {
            if (el.getElementsByTagName("textarea")) {
              el.getElementsByTagName("textarea")[0].focus()
            }
          }
          el.focus()
        }
      }
    },
  }
</script>
